{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "> **SOMETIMES THE QUESTIONS ARE COMPLICATED AND THE ANSWERS ARE SIMPLE **\n",
    "\n",
    ">*Dr. Seuss*\n",
    "\n",
    "## Coin Toss\n",
    "\n",
    "You toss a coin 30 times and see head 24 times. Is it a fair coin?\n",
    "\n",
    "**Hypothesis 1**: Tossing a fair coin will get you 15 heads in 30 tosses. This coin is biased\n",
    "\n",
    "**Hypothesis 2**: Come on, even a fair coin could show 24 heads in 30 tosses. This is just by chance\n",
    "\n",
    "#### Statistical Method\n",
    "\n",
    "P(H) = ? \n",
    "\n",
    "P(HH) = ?\n",
    "\n",
    "P(THH) = ?\n",
    "\n",
    "Now, slightly tougher : P(2H, 1T) = ?\n",
    "\n",
    "Generalizing, \n",
    "\n",
    "<img style=\"float: left;\" src=\"img/binomial.gif\">\n",
    "\n",
    "<br>\n",
    "<br>\n",
    "<br>\n",
    "<br>\n",
    "\n",
    "\n",
    "**What is the probability of getting 24 heads in 30 tosses ?**\n",
    "\n",
    "It is the probability of getting heads 24 times or more. \n",
    "\n",
    "#### Hacker's Approach\n",
    "\n",
    "Simulation. Run the experiment 100,000 times. Find the percentage of times the experiment returned 24 or more heads. If it is more than 5%, we conclude that the coin is biased. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Data of the Experiment: [1 1 0 1 0 0 1 0 0 1 1 0 1 1 0 1 1 0 0 0 0 0 1 0 0 1 1 1 1 0]\n",
      "Heads in the Experiment: [1 1 1 1 1 1 1 1 1 1 1 1 1 1 1]\n",
      "Number of heads in the experiment: 15\n"
     ]
    }
   ],
   "source": [
    "import numpy as np  \n",
    "\n",
    "total_tosses = 30\n",
    "num_heads = 24\n",
    "prob_head = 0.5\n",
    "\n",
    "#0 is tail. 1 is heads. Generate one experiment\n",
    "experiment = np.random.randint(0,2,total_tosses)\n",
    "print \"Data of the Experiment:\", experiment\n",
    "#Find the number of heads\n",
    "print \"Heads in the Experiment:\", experiment[experiment==1]  #This will give all the heads in the array\n",
    "head_count = experiment[experiment==1].shape[0] #This will get the count of heads in the array\n",
    "print \"Number of heads in the experiment:\", head_count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "#Now, the above experiment needs to be repeated 100 times. Let's write a function and put the above code in a loop\n",
    "\n",
    "def coin_toss_experiment(times_to_repeat):\n",
    "\n",
    "    head_count = np.empty([times_to_repeat,1], dtype=int)\n",
    "    \n",
    "    for times in np.arange(times_to_repeat):\n",
    "        experiment = np.random.randint(0,2,total_tosses)\n",
    "        head_count[times] = experiment[experiment==1].shape[0]\n",
    "    \n",
    "    return head_count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "head_count = coin_toss_experiment(100)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[15],\n",
       "       [13],\n",
       "       [15],\n",
       "       [16],\n",
       "       [11],\n",
       "       [16],\n",
       "       [14],\n",
       "       [16],\n",
       "       [13],\n",
       "       [17]])"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "head_count[:10] "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Dimensions: (100, 1) \n",
      "Type of object: <type 'numpy.ndarray'>\n"
     ]
    }
   ],
   "source": [
    "print \"Dimensions:\", head_count.shape, \"\\n\",\"Type of object:\", type(head_count)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "#Let's plot the above distribution\n",
    "import matplotlib.pyplot as plt\n",
    "%matplotlib inline\n",
    "import seaborn as sns\n",
    "sns.set(color_codes = True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.axes._subplots.AxesSubplot at 0x10a2ae350>"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAeIAAAFVCAYAAAAzJuxuAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAGspJREFUeJzt3W9slfX9//HXOaf0HNqeAyU9JmONDJlR77ikKiHGqeH7\nTdeoUbe5DGgb/3BDcIoisvFP7aaAmZlsS1mAmpmMoc0StyBGt2w6ZMNMyE8kYbpNZdPhwF9Liz3n\n9Jz2tNf1vUFkiND2Or2u86ZXn487wIHrXK/3uc75vM5V2nNFXNd1BQAATEStAwAAMJlRxAAAGKKI\nAQAwRBEDAGCIIgYAwBBFDACAoVGL+ODBg2ptbZUkvf/++1q4cKEWLVqkNWvWiJ98AgBgfEYs4o6O\nDq1bt07FYlGS1N7erqVLl+rZZ5/V4OCgdu/eXY6MAACE1ohFPGvWLLW3t586800kEjpx4oRc11Uu\nl9OUKVPKEhIAgLAasYgbGxsVi8VO/bmlpUXr16/XDTfcoJ6eHs2dOzfwgAAAhJmnb9ZauXKlnn32\nWb388su6+eab9cQTT4y6Df+PDADAuVV4+ceFQkHV1dWSpAsuuEAHDhwYdZtIJKKurkxp6SaAdDoZ\n2vnCPJvEfBMd801cYZ5NOjmfF2Mq4kgkIkl6/PHHtWzZMsXjcVVWVuqxxx7znhAAAJwyahHX19er\ns7NTknT11Vfr6quvDjwUAACTBR/oAQCAIYoYAABDFDEAAIYoYgAADFHEAAAYoogBADBEEQMAYIgi\nBgDAEEUMAIAhihgAAEMUMQAAhihiAAAMeboMIhAWjuOor69P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ny/94twxyJDyvf7d83Q8WTx\n20ChoCkVUcWGrJME97iUcvzOt2M0Uha/n5/jyRKEc813vhwj1pZzZfG+7nsu4pqaGuVy/73241hK\nOJ1Oeg5WinT6K/pqWfYEAIA/PJ/GNjQ0aM+ePZKkt956S5dcconvoQAAmCwiruu6XjZwXVdtbW36\n+9//LknauHGjZs+eHUg4AADCznMRAwAA/9h/hxUAAJMYRQwAgCGKGAAAQxQxAACGAivirVu3asGC\nBfrmN7+p3/zmN0HtxoTjOFq9erUWLlyo5uZmHT582DqSbw4ePKjW1lZJ0gcffHBqxra2Nk307+s7\nfbZ33nlHzc3Nam1t1eLFi3X8eHk/CCYIp8/3qV27dmnBggVGifx1+nzHjx/X0qVL1dLSoubmZh05\ncsQ43fidPt/777+vhQsXatGiRVqzZs2Efu0Vi0WtXLlSzc3N+ta3vqVXX301VGvL2ebzvL64AfjL\nX/7i3n333a7rum4ul3N/8pOfBLEbM6+99pp7//33u67runv37nXvu+8+40T+2LZtm3vTTTe53/72\nt13Xdd27777b3bdvn+u6rvvII4+4v//97y3jjcuZs7W0tLjvvPOO67qu29nZ6W7cuNEy3ridOZ/r\nuu5f//pX9/bbb//MbRPVmfN973vfc19++WXXdU+uN6+++qplvHE7c74HHnjAfe2111zXdd0VK1ZM\n6Pmef/55d8OGDa7ruu6JEyfc6667zl2yZElo1pazzed1fQnkjHjv3r265JJLdM8992jJkiWaP39+\nELsxk0gklMlk5LquMpmMpkyZYh3JF7NmzVJ7e/upd6dvv/22rrrqKknStddeq9dff90y3ricOdtT\nTz2lSy+9VJI0NDSkeDxuGW/czpyvt7dXmzZtmvBnU586c74DBw7o2LFjuvPOO7Vr1y7NmzfPOOH4\nnDlfIpHQiRMn5LqucrnchF5jmpqatGzZMkknv5pYUVERqrXlbPNt2rTJ0/oSSBH39PTo0KFD+ulP\nf6rvf//7euihh4LYjZmGhgYNDg6qqalJjzzyiFpaWqwj+aKxsVGxWOzUn09fwKuqqpTJZCxi+eLM\n2dLptKSTFzHZsWOH7rjjDqNk/jh9PsdxtHbtWq1atUpVVVXGyfxx5vH76KOPNG3aND3zzDP6whe+\noI6ODsN043fmfC0tLVq/fr1uuOEG9fT0aO7cuYbpxqeqqkrV1dXKZrO6//779cADD8hxnM/8/URe\nW86cb/ny5aqrq5M09vUlkCKura3VNddco4qKCs2ePVvxeFw9PT1B7MrE008/rYaGBv3ud7/Tzp07\ntWrVKg0ODlrH8t3pnyGey+WUSqUM0/jvpZdeUltbm7Zt26ba2lrrOL45dOiQPvzwQ7W1tWnFihV6\n7733tHHjRutYvpo+ffqpr7TNnz8/dFeBW7lypZ599lm9/PLLuvnmmyf85WaPHj2q22+/Xbfeeqtu\nuumm0K0tp8934403SvK2vgRSxFdccYX+9Kc/SZI+/vhj5fP5UC10+Xxe1dXVkqRUKqVisfiZd3hh\ncdlll2nfvn2SpD179ujKK680TuSfnTt3aseOHdq+fbvq6+ut4/jq8ssv14svvqjt27frqaee0pe/\n/GWtXr3aOpavGhoatHv3bknSvn37dPHFF9sG8lmhUDi1xlxwwQXq6+szTlS67u5u3XXXXVq5cqW+\n8Y1vSArX2nK2+byuL56vvjQW119/vfbv36/bbrtNjuPo0UcfVSQSCWJXJhYvXqzVq1dr0aJFGhoa\n0ooVK5RIJKxj+ebTY7Vq1So9/PDDKhaLmjNnjpqamoyTjV8kEpHjONqwYYNmzpype++9V5I0d+5c\n3Xfffcbpxu/M15nruqF67Z3+3Fy3bp2ee+45pVIp/ehHPzJO5o9P53v88ce1bNkyxeNxVVZW6rHH\nHjNOVrotW7Yok8lo8+bN2rx5syRp7dq1Wr9+fSjWljPncxxH7777rr74xS+OeX3hs6YBADDEB3oA\nAGCIIgYAwBBFDACAIYoYAABDFDEAAIYoYgAADFHEAAAY+j954m43MqFUVwAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x10691fb50>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "sns.distplot(head_count, kde=False)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**Exercise**: Try setting `kde=True` in the above cell and observe what happens"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([], dtype=int64)"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#Number of times the experiment returned 24 heads.\n",
    "head_count[head_count>=24]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "No of times experiment returned 24 heads or more: 0\n",
      "% of times with 24 or more heads:  0.0\n"
     ]
    }
   ],
   "source": [
    "print \"No of times experiment returned 24 heads or more:\", head_count[head_count>=24].shape[0]\n",
    "print \"% of times with 24 or more heads: \", head_count[head_count>=24].shape[0]/float(head_count.shape[0])*100"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "####  Exercise: Repeat the experiment 100,000 times. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Is the coin fair?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Extra pointers on numpy"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**** Removing `for` loop in the funciton ****"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "def coin_toss_experiment_2(times_to_repeat):\n",
    "\n",
    "    head_count = np.empty([times_to_repeat,1], dtype=int)\n",
    "    experiment = np.random.randint(0,2,[times_to_repeat,total_tosses])\n",
    "    return experiment.sum(axis=1)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Exercise: Benchmark `coin_toss_experiment` and `coin_toss_experiment_2` for 100 and 100,000 runs and report improvements, if any"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
